package com.mndp.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mndp.common.vo.Result;
import com.mndp.system.domain.po.TestPeople;
import com.mndp.system.domain.vo.TestPeopleAddVo;
import com.mndp.system.domain.vo.TestPeoplePageVo;
import com.mndp.system.service.TestPeopleService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 *
 */
@Controller
@RequestMapping("/test")
public class TestPeopleController  {

    @Resource
    private TestPeopleService testPeopleService;

    /**
     * 跳转页面
     */
    @RequestMapping("")
    public String index() {
        return "index.html";
    }

    /**
     * 测试数据-MP分页
     */
    @ResponseBody
    @GetMapping("/list1")
    public Result list1(TestPeoplePageVo vo) {
        IPage<TestPeople> page = testPeopleService.getPage1(vo);
        return Result.ok(page);
    }

    /**
     * 测试数据-自写分页
     */
    @ResponseBody
    @GetMapping("/list2")
    public Result list2(TestPeoplePageVo vo) {
        IPage<TestPeople> page = testPeopleService.getPage2(vo);
        return Result.ok(page);
    }

    /**
     * 测试数据-新增
     */
    @ResponseBody
    @PostMapping
    public Result add(@Validated @RequestBody TestPeopleAddVo vo) {
        testPeopleService.addInfo(vo);
        return Result.ok();
    }

    /**
     * 测试数据-查询
     */
    @ResponseBody
    @GetMapping(value = "/{id}")
    public Result query(@PathVariable String id) {
        TestPeople testPeople = testPeopleService.getInfo(id);
        return Result.ok(testPeople);
    }

}
